package com.zj.mapping;

import com.zj.enu.SqlType;
import com.zj.utils.GenericTokenParser;
import com.zj.utils.ParameterMappingTokenHandler;

public class MappedStatement {
    private String id;
    private String sql;
    private String resultType;
    private String paramterType;
    private SqlType sqlType;

    public SqlType getSqlType() {
        return sqlType;
    }

    public void setSqlType(SqlType sqlType) {
        this.sqlType = sqlType;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public String getResultType() {
        return resultType;
    }

    public void setResultType(String resultType) {
        this.resultType = resultType;
    }

    public String getParamterType() {
        return paramterType;
    }

    public void setParamterType(String paramterType) {
        this.paramterType = paramterType;
    }
    //解析sql，将#{xx}替换为点位符?，并将xx存于list（面向对象思想，返回一个BoundSql对象）
    public BoundSql getBoundSql( ) {
        ParameterMappingTokenHandler parameterMappingTokenHandler = new ParameterMappingTokenHandler();
        GenericTokenParser genericTokenParser = new GenericTokenParser("#{", "}", parameterMappingTokenHandler);
        String sqlText = genericTokenParser.parse(getSql());
        return new BoundSql(sqlText,parameterMappingTokenHandler.getParameterMappings());
    }
}
